package com.eedi.org.healthinfo.controller;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.common.validation.AddGroup;
import com.eedi.framework.common.validation.UpdateGroup;
import com.eedi.org.healthinfo.controller.vo.OrgHealthInfoPageReqVO;
import com.eedi.org.healthinfo.controller.vo.OrgHealthInfoRespVO;
import com.eedi.org.healthinfo.controller.vo.OrgHealthInfoSaveReqVO;
import com.eedi.org.healthinfo.controller.vo.OrgHealthInfoUpdateStatusReqVO;
import com.eedi.org.healthinfo.dal.dataobject.OrgHealthInfoDO;
import com.eedi.org.healthinfo.service.OrgHealthInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.eedi.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 健康资讯")
@RestController
@RequestMapping("/health-info")
@Validated
public class OrgHealthInfoController {

    @Resource
    private OrgHealthInfoService orgHealthInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建健康资讯")
    @PermitAll
  //  @PreAuthorize("@ss.hasPermission('org:health-info:create')")
    public CommonResult<String> createHealthInfo(@Validated({AddGroup.class}) @RequestBody OrgHealthInfoSaveReqVO createReqVO) {
        return success(orgHealthInfoService.createHealthInfo(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新健康资讯")
    @PermitAll
    //    @PreAuthorize("@ss.hasPermission('org:health-info:update')")
    public CommonResult<Boolean> updateHealthInfo(@Validated({UpdateGroup.class}) @RequestBody OrgHealthInfoSaveReqVO updateReqVO) {
        orgHealthInfoService.updateHealthInfo(updateReqVO);
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除健康资讯")
    @PermitAll
    @Parameter(name = "orgHealthInfoId", description = "编号", required = true)
    //   @PreAuthorize("@ss.hasPermission('org:health-info:delete')")
    public CommonResult<Boolean> deleteHealthInfo(String orgHealthInfoId) {
        orgHealthInfoService.deleteHealthInfo(orgHealthInfoId);
        return success(true);
    }

    @PostMapping("/update-status")
    @Operation(summary = "修改健康资讯分类状态")
    //   @PreAuthorize("@ss.hasPermission('org:health-info:updateStatus')")
    @PermitAll
    public CommonResult<Boolean> updateHealthInfoStatus(@Valid @RequestBody OrgHealthInfoUpdateStatusReqVO reqVO) {
        orgHealthInfoService.updateHealthInfoStatus(reqVO);
        return success(true);
    }

    @PostMapping("/page")
    @Operation(summary = "获得健康资讯分页")
    @PermitAll
    //   @PreAuthorize("@ss.hasPermission('org:health-info:query')")
    public CommonResult<PageResult<OrgHealthInfoRespVO>> getHealthInfoPage(@RequestBody OrgHealthInfoPageReqVO pageReqVO) {
        PageResult<OrgHealthInfoDO> pageResult = orgHealthInfoService.getHealthInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, OrgHealthInfoRespVO.class));
    }


}
